<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../resources/common.js"></script>
<script src="../resources/picker-common.js"></script>
<script src="../calendar-picker/resources/calendar-picker-common.js"></script>
</head>
<body>
<input type="datetime-local" id="datetime-local-0" value="2019-05-22T13:02" max="2019-06-15T13:02">
<input type="datetime-local" id="datetime-local-1" value="2019-11-20T13:02" min="2019-10-29T13:02">
<script>

promise_test(() => {
  let dateTimeElement = document.getElementById('datetime-local-0');
  return openPickerWithPromise(dateTimeElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickNextMonthButton();
    assert_equals(dateTimeElement.value, "2019-06-15T13:02", "Month chooser button should have changed month and stopped at max date");

    clickDayCellAt(2, 2);
    eventSender.keyDown('Enter');
    assert_equals(dateTimeElement.value, "2019-06-11T13:02", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Popup should have closed");
  });
}, "Datetimelocal picker: Next month button should advance to next month and clip selection to max date.");

promise_test(() => {
  let dateTimeElement = document.getElementById('datetime-local-1');
  return openPickerWithPromise(dateTimeElement)
  .then(() => {
    // Make the picker dismiss synchronously so we don't need to insert
    // an artificial delay in the test
    internals.pagePopupWindow.CalendarPicker.commitDelayMs = 0;

    clickPrevMonthButton();
    assert_equals(dateTimeElement.value, "2019-10-29T13:02", "Month chooser button should have changed month and stopped at min date");

    clickDayCellAt(4, 4);
    eventSender.keyDown('Enter');
    assert_equals(dateTimeElement.value, "2019-10-31T13:02", "Clicking date should have changed date");
    assert_equals(internals.pagePopupWindow, null, "Popup should have closed");
  });
}, "Datetimelocal picker: Previous month button should advance to previous month and clip selection to min date.");
</script>
</body>
</html>
